package cn.ichiva.dl.tushare.common;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.nd4j.linalg.api.ndarray.INDArray;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * 可评分AI
 */
@Slf4j
@Getter
@Setter
public class ScoreAgent extends Agent {
    private static final AtomicInteger index = new AtomicInteger(0);

    /**
     * 世代
     *
     * 母本世代+1
     */
    private int generation;

    /**
     * 编号
     */
    private int number;

    /**
     * 评分
     */
    private List<Double> scores;

    public ScoreAgent(AgentConfig config) {
        this(config,null);
    }

    public ScoreAgent(AgentConfig config, INDArray dna) {
        super(config, dna);
        int number = index.incrementAndGet();
        if(number % 100 == 1) log.info("agent number = {}",number);
        this.number = number;
        this.scores = new ArrayList<>();
    }

    @Override
    public String getName() {
        return String.format("P2G%sN%s",generation,number);
    }

    @Override
    public String toString() {
        String scoreText = scores.stream().map(e -> e.toString()).collect(Collectors.joining(",", "[", "]"));
        return String.format("Agent name = %s, score = %s",getName(), scoreText);
    }
}
